package com.sn.controller;

import com.sn.core.component.page.Pagination;
import com.sn.core.http.CommRequest;
import com.sn.model.ChargeOrder;
import com.sn.model.Customer;
import com.sn.model.CustomerScore;
import com.sn.model.req.CustomerScoreLogReq;
import com.sn.model.req.CustomerScoreReq;
import com.sn.model.req.OrderReq;
import com.sn.model.vo.CustomerScoreLogVo;
import com.sn.model.vo.CustomerScoreVo;
import com.sn.service.CustomerScoreService;
import com.sn.service.OrderService;
import com.sn.service.UserService;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by qingshengzheng on 18/6/21.
 */
@RequestMapping(value = "score")
@Controller
@EnableAutoConfiguration
public class ScoreController extends BaseController {

    @Resource
    private UserService userService;
    @Resource
    private OrderService orderService;

    @Resource
    private CustomerScoreService scoreService;

    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/addOrder")
    @ResponseBody
    @Transactional
    public Object addOrder(@RequestBody CommRequest<OrderReq> userQueryCommRequest) {
       //创建订单
        OrderReq orderReq=userQueryCommRequest.getData();
        orderService.addOrder(userQueryCommRequest.getData());
        //获取上级用户




        //写积分log
        return responseJson(null);
    }
    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/queryScoreLog")
    @ResponseBody
    @Transactional
    public Object queryScoreLog(@RequestBody CommRequest<CustomerScoreLogReq> userQueryCommRequest) {
       Object o= scoreService.queryCustomerScoreLog(userQueryCommRequest.getData());
        return responseJson(o);
    }
    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/queryScores")
    @ResponseBody
    @Transactional
    public Object queryScores(@RequestBody CommRequest<CustomerScoreReq> userQueryCommRequest) {
        Object o= scoreService.queryScores(userQueryCommRequest.getData());
        return responseJson(o);
    }


}
